package com.esri.core.internal.catalog;

import com.esri.core.geometry.Envelope;
import com.esri.core.geometry.SpatialReference;
import com.tencent.smtt.sdk.TbsVideoCacheTask;
import java.io.PrintStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import org.achartengine.internal.a;
import org.codehaus.jackson.JsonParseException;
import org.codehaus.jackson.JsonParser;
import org.codehaus.jackson.JsonToken;

/* loaded from: classes.dex */
public class Item implements PageableResultType {
    int A;
    ItemType B;
    Catalog C;
    private String D;
    String a;
    String b;
    String c;
    String d;
    User e;
    Date f;
    Date g;
    String h;
    String i;
    String j;
    List<String> k;
    String l;
    List<String> m;
    String n;
    String o;
    byte[] p;
    String q;
    Envelope r;
    SpatialReference s;
    String t;
    String u;
    String v;
    int w;
    int x;
    int y;
    float z;

    /* loaded from: classes.dex */
    public enum ItemType {
        WEB_MAP,
        FEATURE_COLLECTION
    }

    /* loaded from: classes.dex */
    public enum SortField {
        TITLE { // from class: com.esri.core.internal.catalog.Item.SortField.1
            @Override // java.lang.Enum
            public String toString() {
                return a.b;
            }
        },
        UPLOADED { // from class: com.esri.core.internal.catalog.Item.SortField.2
            @Override // java.lang.Enum
            public String toString() {
                return "uploaded";
            }
        },
        TYPE { // from class: com.esri.core.internal.catalog.Item.SortField.3
            @Override // java.lang.Enum
            public String toString() {
                return "type";
            }
        },
        OWNER { // from class: com.esri.core.internal.catalog.Item.SortField.4
            @Override // java.lang.Enum
            public String toString() {
                return "owner";
            }
        },
        AVG_RATING { // from class: com.esri.core.internal.catalog.Item.SortField.5
            @Override // java.lang.Enum
            public String toString() {
                return "avgrating";
            }
        },
        NUM_RATINGS { // from class: com.esri.core.internal.catalog.Item.SortField.6
            @Override // java.lang.Enum
            public String toString() {
                return "numratings";
            }
        },
        NUM_COMMENTS { // from class: com.esri.core.internal.catalog.Item.SortField.7
            @Override // java.lang.Enum
            public String toString() {
                return "numcomments";
            }
        },
        NUM_VIEWS { // from class: com.esri.core.internal.catalog.Item.SortField.8
            @Override // java.lang.Enum
            public String toString() {
                return "numviews";
            }
        }
    }

    private static ItemType a(String str) {
        if (str.equals("Web Map")) {
            return ItemType.WEB_MAP;
        }
        if (str.equals("Feature Collection")) {
            return ItemType.FEATURE_COLLECTION;
        }
        return null;
    }

    /* JADX INFO: Access modifiers changed from: protected */
    public Item(URL url) {
    }

    public Item() {
    }

    @Override // com.esri.core.internal.catalog.PageableResultType
    public boolean fromJson(JsonParser jsonParser, Filter filter, Catalog catalog) throws Exception {
        this.C = catalog;
        while (jsonParser.nextToken() != JsonToken.END_OBJECT) {
            String currentName = jsonParser.getCurrentName();
            jsonParser.nextToken();
            if (currentName.equals("id")) {
                this.a = jsonParser.getText();
            } else if (currentName.equals("item")) {
                this.b = jsonParser.getText();
            } else if (currentName.equals("itemType")) {
                this.c = jsonParser.getText();
            } else if (currentName.equals("owner")) {
                this.d = jsonParser.getText();
            } else if (currentName.equals("uploaded")) {
                if (jsonParser.getCurrentToken() == JsonToken.VALUE_STRING) {
                    this.f = new Date(new Long(jsonParser.getText()).longValue());
                } else if (jsonParser.getCurrentToken() == JsonToken.VALUE_NUMBER_INT) {
                    this.f = new Date(jsonParser.getLongValue());
                }
            } else if (currentName.equals("modified")) {
                if (jsonParser.getCurrentToken() == JsonToken.VALUE_STRING) {
                    this.g = new Date(new Long(jsonParser.getText()).longValue());
                } else if (jsonParser.getCurrentToken() == JsonToken.VALUE_NUMBER_INT) {
                    this.g = new Date(jsonParser.getLongValue());
                }
            } else if (currentName.equals("guid")) {
                this.h = jsonParser.getText();
            } else if (currentName.equals("name")) {
                this.i = jsonParser.getText();
            } else if (currentName.equals(a.b)) {
                this.j = jsonParser.getText();
            } else if (currentName.equals("type")) {
                this.B = a(jsonParser.getText());
            } else if (currentName.equals("typeKeywords")) {
                this.k = new ArrayList();
                while (jsonParser.nextToken() != JsonToken.END_ARRAY) {
                    this.k.add(jsonParser.getText());
                }
            } else if (currentName.equals("description")) {
                this.l = jsonParser.getText();
            } else if (currentName.equals("tags")) {
                this.m = new ArrayList();
                while (jsonParser.nextToken() != JsonToken.END_ARRAY) {
                    this.m.add(jsonParser.getText());
                }
            } else if (currentName.equals("snippet")) {
                this.n = jsonParser.getText();
            } else if (currentName.equals("thumbnail")) {
                this.o = jsonParser.getText();
            } else if (currentName.equals("documentation")) {
                this.q = jsonParser.getText();
            } else if (currentName.equals("extent")) {
                if (jsonParser.getText().equals("null")) {
                    this.r = null;
                } else {
                    jsonParser.nextToken();
                    try {
                        if (jsonParser.getCurrentToken() == JsonToken.START_ARRAY) {
                            jsonParser.nextToken();
                            double doubleValue = jsonParser.getDoubleValue();
                            jsonParser.nextToken();
                            double doubleValue2 = jsonParser.getDoubleValue();
                            jsonParser.nextToken();
                            jsonParser.nextToken();
                            jsonParser.nextToken();
                            double doubleValue3 = jsonParser.getDoubleValue();
                            jsonParser.nextToken();
                            double doubleValue4 = jsonParser.getDoubleValue();
                            jsonParser.nextToken();
                            jsonParser.nextToken();
                            this.r = new Envelope(doubleValue, doubleValue2, doubleValue3, doubleValue4);
                        }
                    } catch (JsonParseException unused) {
                        PrintStream printStream = System.err;
                        printStream.println("Error occurred while parsing the extent field of this Item : " + this.a);
                    }
                }
            } else if (currentName.equals("spatialReference")) {
                String text = jsonParser.getText();
                if (text == null || text.equals("null")) {
                    this.s = null;
                } else {
                    try {
                        try {
                            this.s = SpatialReference.create(Integer.parseInt(text));
                        } catch (NumberFormatException unused2) {
                            this.s = SpatialReference.create(jsonParser.getText());
                        }
                    } catch (Exception unused3) {
                        PrintStream printStream2 = System.err;
                        printStream2.println("Unable to construct spatial reference from " + jsonParser.getText());
                    }
                }
            } else if (currentName.equals("accessInformation")) {
                this.v = jsonParser.getText();
            } else if (currentName.equals("licenseInfo")) {
                this.t = jsonParser.getText();
            } else if (currentName.equals(TbsVideoCacheTask.KEY_VIDEO_CACHE_PARAM_URL)) {
                this.u = jsonParser.getText();
            } else if (currentName.equals("access")) {
                this.v = jsonParser.getText();
            } else if (currentName.equals("size")) {
                this.y = jsonParser.getIntValue();
            } else if (currentName.equals("numComments")) {
                this.w = jsonParser.getIntValue();
            } else if (currentName.equals("numRatings")) {
                this.x = jsonParser.getIntValue();
            } else if (currentName.equals("avgRating")) {
                this.z = jsonParser.getFloatValue();
            } else if (currentName.equals("numViews")) {
                this.A = jsonParser.getIntValue();
            }
        }
        return filter == null || this.B == filter.a;
    }

    public String getId() {
        return this.a;
    }

    public User getOwner() throws CatalogException {
        throw new CatalogException("Not implemeted yet");
    }

    public String getOwnerName() {
        return this.d;
    }

    public Date getUploaded() {
        return this.f;
    }

    public Date getModifiedDate() {
        return this.g;
    }

    public String getGuid() {
        return this.h;
    }

    public String getName() {
        return this.i;
    }

    public URL getUrl() {
        try {
            if (this.u != null) {
                return new URL(this.u);
            }
            return null;
        } catch (MalformedURLException e) {
            e.printStackTrace();
            return null;
        }
    }

    public String getTitle() {
        return this.j;
    }

    public List<String> getKeywords() {
        return this.k;
    }

    public String getDescription() {
        return this.l;
    }

    public List<String> getTags() {
        return this.m;
    }

    public String getSnippet() {
        return this.n;
    }

    public byte[] getThumbnail() {
        try {
            if (this.p == null) {
                String str = this.C.getUrl() + "/content/items/" + this.a + "/info/" + this.o;
                HashMap hashMap = new HashMap();
                if (this.C.getUserToken() != null) {
                    hashMap = new HashMap();
                    hashMap.put("token", this.C.getUserToken());
                }
                this.p = com.esri.core.internal.io.handler.a.a(str, hashMap, this.C.a());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return this.p;
    }

    public byte[] getThumbnailIfExists() {
        byte[] bArr = this.p;
        if (bArr == null) {
            return null;
        }
        return bArr;
    }

    public void clear() {
        this.p = null;
        this.t = null;
        this.a = null;
        this.b = null;
        this.c = null;
        this.d = null;
        this.e = null;
        this.f = null;
        this.g = null;
        this.h = null;
        this.i = null;
        this.j = null;
        this.k = null;
        this.l = null;
        this.m = null;
        this.n = null;
        this.o = null;
        this.p = null;
        this.q = null;
        this.r = null;
        this.s = null;
        this.t = null;
        this.u = null;
        this.v = null;
        this.B = null;
        this.C = null;
    }

    public String getDocumentation() {
        return this.q;
    }

    public Envelope getExtent() {
        return this.r;
    }

    public SpatialReference getSpRef() {
        return this.s;
    }

    public String getLicenseInfoHtml() {
        return this.t;
    }

    public String getAccess() {
        return this.v;
    }

    public int getNumComments() {
        return this.w;
    }

    public int getNumRatings() {
        return this.x;
    }

    public int getSize() {
        return this.y;
    }

    public float getAvgRating() {
        return this.z;
    }

    public int getNumViews() {
        return this.A;
    }

    public ItemType getType() {
        return this.B;
    }

    @Override // com.esri.core.internal.catalog.PageableResultType
    public <T extends PageableResultType> int compare(T t) {
        Item item = (Item) t;
        if (this.f.before(item.f)) {
            return -1;
        }
        return this.f.after(item.f) ? 1 : 0;
    }

    public String getMCSAddress() {
        return this.D;
    }

    public void setMCSAddress(String str) {
        this.D = str;
    }
}
